package com.lifang.test5;

import com.lifang.framework.context.support.AnnotationConfigApplicationContext;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
public class TestApp {

    /**
     * aop + ioc + 循环依赖 + 基本生命周期，Aware感知，初始化 销毁方法
     * <p>
     * 广播，观察者
     * ApplicationRefreshEvent         容器刷新完成广播
     * ApplicationContextClosedEvent   容器关闭广播
     * CustomEventListener             自定义广播
     */
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(TestApp.class);

        Map<String, UserService> beansOfType = applicationContext.getBeansOfType(UserService.class);
        for (Map.Entry<String, UserService> entry : beansOfType.entrySet()) {
            UserService value = entry.getValue();
            value.sayHello("张三");
            log.info(value.sayHelloReturn("张三") + "\n");
        }

        applicationContext.publishEvent(new CustomEvent(applicationContext, "这是广播事件的message"));
    }

}
